{% extends 'base/base.html' %}
{% load tags %}

{% block title %}ITAdmin | 终端--当前连接:{{ host_name }}{% endblock %}


{% block body %}

<script type="text/javascript" src="/static/gateone/gateone.js"></script>
<div>
     当前连接： <strong>{{ host_name }}</strong>

    <div id="gateone_container" style="position: relative; width: 100%; height: 50em;margin: 0 auto">

        <div id="gateone"></div>

    </div>
</div>
<script type="application/javascript" src="/static/js/jquery-2.1.1.js"></script>

{% endblock %}


{% block script %}

<script type="text/javascript">
    $(document).ready(function(){
        var ip = '{{ host_ip }}';
        var user = '{{ host_user }}';
        var port = {{ host_port }};
        var ssh_url = 'ssh://'+user +'@'+ip+':'+port;
        <!--去请求认证信息-->
        var request = $.ajax({
            url:'{% url "get_auth_obj" %}',   // api认证方式，
            type:"GET",
            dataType:"json"
        });

        <!--根据认证信息去连接websocket -->
        request.done(function(auth_info){
            console.log(auth_info.auth);
            var auth_message = auth_info.auth;
            var auth_url = auth_info.url;
            GateOne.init({
                auth: auth_message,
                url: auth_url,
                theme: 'solarized',
                goDiv: '#gateone',
                autoConnectURL:ssh_url,
                showToolbar: false
            });

        });
        GateOne.Base.superSandbox("GateOne.SomePlugin", ["GateOne", "GateOne.Net",  "GateOne.Terminal.Input", "GateOne.Terminal"], function(window, undefined) {

            var location =  ip;
            GateOne.prefs.autoConnectURL=ssh_url;
            GateOne.prefs.fontSize="100%";
            GateOne.prefs.scrollback = 10000;  // scrollback buffer up to 10,000 lines
            GateOne.Terminal.loadFont("Source Code Pro", "100%");
            GateOne.locations; // Holds the state of all current known/open locations
            GateOne.Net.setLocation(location);
            <!--记录登录状态-->

        });
    });
</script>

{% endblock %}